//
// Created by snake on 2022/11/8.
//

// #ifndef AOS_FILE_HPP
// #define AOS_FILE_HPP
#pragma once

#include <optional>
#include <vector>
#include <filesystem>
#include <iostream>
// #include <memory>

using namespace std;
namespace fs = filesystem;

/**
 * 根据所给文件、条件得到文件清单
 * @param filename 文件名
 * @param filelist 文件清单
 * @param suffix 后缀
 */
void getfilelist_r(const string &filename, vector<string> &filelist, const string &suffix = "") {
    switch (fs::status(filename).type()) {
        case fs::file_type::regular:
            if (filename.ends_with(suffix)) {
                filelist.emplace_back(filename);
            }
            break;
        case fs::file_type::directory:
            for (auto &p: fs::directory_iterator(filename)) {
                getfilelist_r(p.path().string(), filelist, suffix);
            }
            break;
        default:
            break;
    }
}

// #endif //AOS_FILE_HPP
